package com.amor.util

import android.content.Context
import android.webkit.WebSettings
import com.amor.widget.ExWebView

class WebViewHolder(private val cxt: Context) {

    private val caches = HashMap<String, ExWebView>()

    fun build(flag: String? = null): ExWebView {
        val key = flag ?: FLAG_DEFAULT
        if (caches.containsKey(key)) {
            val web = caches[key]
            web!!.strip()
            return web
        }
        val web = ExWebView(cxt)
        caches[key] = web
        return web
    }

//    fun buildArticle(): ExWebView {
//        val key = FLAG_ARTICLE
//        val has = caches.containsKey(key)
//        val web = build(key)
//        if (!has) {
//            web.strip()
//            web.initWebSettings(WebSettings.LOAD_DEFAULT)
//            web.loadUrl("https://m.huize.com/zhishi/tuijian/0")
//        }
//        return web
//    }

    companion object {
        const val FLAG_DEFAULT = "default"
        const val FLAG_SHOP = "shop"
        const val FLAG_ARTICLE = "article"
    }
}